package com.woniu.humanresource.controller;

import com.woniu.humanresource.entity.Purchase;
import com.woniu.humanresource.entity.PurchaseList;
import com.woniu.humanresource.entity.ResponseText;
import com.woniu.humanresource.service.PurchaseListService;
import com.woniu.humanresource.service.PurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

@RestController
public class PurchaseListController {
    @Autowired
    PurchaseListService purchaseListService;

    //查询所有
//    @PostMapping("/warehouse")
//    public ResponseText<List<Warehouse>> getAllWarehouse(){
//
//        List<Warehouse> allWarehouse = warehouseService.getAllWarehouse();//调service方法去查询
//        ResponseText<List<Warehouse>> responseText=new ResponseText<>(allWarehouse, 200, "OK");//返回一个带有树状的分类
//        return responseText;
//    }

    //添加根节点
//    @PostMapping("/addRootNodeWarehouse/{newWarehouseName}/{newWarehouseNum}/{newWarehouseAddress}/{newWarehouseRemarks}")
//    public ResponseText<List<Warehouse>> addRootNodeWarehouse(@PathVariable("newWarehouseName") String newWarehouseName,
//                                                                   @PathVariable("newWarehouseNum") String newWarehouseNum,
//                                                                   @PathVariable("newWarehouseAddress") String newWarehouseAddress,
//                                                                   @PathVariable("newWarehouseRemarks") String newWarehouseRemarks){
//
//        System.out.println("■■■■■■添加■■■■■■"+newWarehouseName+"/"+newWarehouseNum+"/"+newWarehouseAddress+"/"+newWarehouseRemarks);
//
//        warehouseService.addRootNodeWarehouse(newWarehouseName,newWarehouseNum,newWarehouseAddress,newWarehouseRemarks);//调service方法去插入
//        ResponseText<List<Warehouse>> responseText=new ResponseText<>(null, 200, "OK");//返回一个空信息的状态响应
//        return responseText;
//    }

    //添加子节点分类
    @PostMapping("/addPurchaseList")
    public ResponseText<List<PurchaseList>> addPurchaseList(@RequestBody PurchaseList[] purchases){

        System.out.println("■■■■■■添加■■■■■■"+ Arrays.toString(purchases));

        purchaseListService.addPurchaseList(purchases);//调service方法去插入
        ResponseText<List<PurchaseList>> responseText=new ResponseText<>(null, 200, "OK");//返回一个空信息的状态响应
        return responseText;
    }

    //根据pid查询
    @PostMapping("/getPurchaseListByPid/{purchaseid}")
    public ResponseText<List<PurchaseList>> getPurchaseListByPid(@PathVariable("purchaseid") int purchaseid){
        System.out.println("■■■■■■查询***■■■■■■"+purchaseid);

        List<PurchaseList> purchaseLists = purchaseListService.getPurchaseListByPid(purchaseid);

        ResponseText<List<PurchaseList>> responseText=new ResponseText<>(purchaseLists, 200, "OK");
        return responseText;
    }

    //删除
//    @DeleteMapping("/removeWarehouse")
//    public ResponseText<Page<Warehouse>> removeWarehousesByIds(@RequestBody List<Warehouse> warehouses){
//
//        System.out.println("■■■■■■删除■■■■■■"+warehouses);
//
//        warehouseService.removeWarehousesByIds(warehouses);
//        ResponseText<Page<Warehouse>> responseText=new ResponseText<>(null, 200, "OK");
//        return responseText;
//    }

    //编辑
//    @PutMapping("/editWarehouse/{newWarehouseName}/{newWarehouseNum}/{newWarehouseAddress}/{newWarehouseRemarks}")
//    public ResponseText<List<Warehouse>> editWarehouse(@PathVariable("newWarehouseName") String newWarehouseName,
//                                                                 @PathVariable("newWarehouseNum") String newWarehouseNum,
//                                                                 @PathVariable("newWarehouseAddress") String newWarehouseAddress,
//                                                                 @PathVariable("newWarehouseRemarks") String newWarehouseRemarks,
//                                                                 @RequestBody Warehouse warehouse){
//
//        System.out.println("■■■■■■编辑■■■■■■"+newWarehouseName+"/"+newWarehouseNum+"/"+newWarehouseAddress+"/"+newWarehouseRemarks+"/"+warehouse);
//
//        warehouseService.editWarehouse(newWarehouseName,newWarehouseNum,newWarehouseAddress,newWarehouseRemarks,warehouse);//调service方法去插入
//        ResponseText<List<Warehouse>> responseText=new ResponseText<>(null, 200, "OK");//返回一个空信息的状态响应
//        return responseText;
//    }
}
